<template>
	<uni-drawer ref="showUserList" mode="left" :width="250">
		<view class="close">
			<view>
				当前用户：{{merchantName}}
			</view>
			<uni-icons type="close" :size="25" color="#ff0000" @click="close"></uni-icons>
		</view>
		<view class="scroll-view">
			<scroll-view class="scroll-view-box" scroll-y="true">
				<xtx-treeNode :list="list" @change="treeChange"></xtx-treeNode>
			</scroll-view>
		</view>
	</uni-drawer>
</template>

<script>
	
	export default {
		data() {
			return {
				merchantName: uni.getStorageSync('mname')
			}
		},
		
		props: {
			list: {
				type: Array,
				default: () => [],
				required: true
			}
		},
		
		methods: {
			show( ) {
				this.$refs.showUserList.open()
			},
			
			close() {
				this.$refs.showUserList.close()
			},
			
			treeChange(e) {
				uni.showModal({
					title: '确认切换吗？',
					content: `切换为用户：${e.name}`,
					success: res => {
						if(res.confirm) {
							uni.setStorageSync('mid', e.id)
							uni.setStorageSync('mname', e.name)
							this.$emit('changeMerchant', e.id)
							this.close();
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scroll-view {
		width: 100%;
		height: 100%;
	}
	
	.scroll-view-box {
		position: absolute;
		top: 100rpx;
		right: 0;
		bottom: 0;
		left: 0;
	}
	
	.close {
		padding: 0 20rpx 0 50rpx;
		height: 100rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
</style>